package com.songhq.data.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.songhq.data.bean.Figure;
import com.songhq.data.bean.PageVO;
import com.songhq.data.mapper.FigureMapper;
import com.songhq.data.utils.UUIDUtils;

@Service
public class FigureService {
	
	
	@Autowired
	private FigureMapper figureMapper;

	public PageVO listFigures(Figure figure) {
		//使用分页查询helper
		PageHelper.startPage(figure.getPageNumber(), figure.getPageSize());
		//执行查询
		List<Figure> list = figureMapper.listFigure(figure);
		//取分页结果
		PageInfo<Figure> pageInfo = new PageInfo<>(list);
		//创建一个返回值对象
		PageVO<Figure> pageBean = new PageVO<Figure> ();
		pageBean.setList(list);
		//取总记录数
		long total = pageInfo.getTotal();
		pageBean.setCount(total);
		return pageBean;
	}

	public Figure getOneFigure(String figureId) {
		
		Figure figure = figureMapper.getOneFigure(figureId);
		return figure;
	}

	//新增
	public void saveFigure(Figure figure) {
		//生成主键id
		String generateUUID = UUIDUtils.generateUUID();
		figure.setFigureId(generateUUID);
		figureMapper.insert(figure);
	}

	public void updateFigure(Figure figure) {
		
		figureMapper.updateFigure(figure);
		
	}

	public void deleteFigure(Figure figure) {
		
		figureMapper.deleteFigure(figure);
	}
	
	
	
	

}
